#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
#include<climits>
#include<algorithm>

using namespace std;

int main()
{
    int n = 0;
    string s;
    cin >> n;
    cin >> s;
    vector<vector<int>>hashi(n + 1, vector<int>(26));
    for (int i = n - 1; i >= 0; i--)
    {
        hashi[i] = hashi[i + 1];
        hashi[i][s[i] - 'a']++;
    }
    long long sum = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < 26; j++)
        {
            if (j != s[i] - 'a')
            {
                //cout<<hashi[i][j]<<' ';
                int x = hashi[i + 1][j];
                sum += x * (x - 1) / 2;
            }
        }
    }
    cout << sum;
    return 0;
}